
// 邮箱正则
export const Email = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/
// url 正则
export const Url = /^((https?|ftp|file):\/\/)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/

// textarea 多邮箱验证
// 返回一个字符串 or undefined
// 字符串代表错误提示 undefined 代表通过
export function emailAreaTest(emailArea) {
  let notic
  if (!emailArea.trim()) {
    notic = 'Please enter the email'
  } else {
    const emailTrimArray = []
    emailArea.split('\n').forEach(item => {
      if (item && item.trim()) {
        emailTrimArray.push(item.trim())
      }
    })
    // console.log(emailTrimArray)
    for (let i = 0, l = emailTrimArray.length; i < l; i++) {
      if (!Email.test(emailTrimArray[i])) {
        notic = `Please enter the correct email  ${emailTrimArray[i]}`; break
      }
    }
  }
  return notic
}
// 价格正则 允许输入小数
export const Price = /^(0|([1-9]\d*))(\.\d+)?$/
